package com.service;

import com.bean.EDelivery;
import com.dao.BaseEDeliveryDao;
import com.dao.imp.EDeliveryDaoMysql;
import com.exception.NumberException;
import com.exception.idNumberException;
import com.exception.phoneException;

import java.util.List;
import java.util.Map;

/**
 * @author LEIKE
 * @Title : EDeliverService
 * @Description: 快递员业务Service
 * @Date_Created_in: 2021/5/27 12:20
 * @Modified_By:
 * @Project: com.service
 */
public class EDeliverService {
    private static BaseEDeliveryDao dao = new EDeliveryDaoMysql();

    public static Map<String, Integer> console() {
        return dao.console();
    }

    public static List<EDelivery> findAll(boolean limit, int offset, int pageNumber) {
        return dao.findAll(limit, offset, pageNumber);
    }

    public static List<EDelivery> findByPhoneNumber(String phoneNumber) {
        return dao.findByPhoneNumber(phoneNumber);
    }

    public static boolean insert(EDelivery newE)  {
        boolean insert = false;
        try {
            insert = dao.insert(newE);
        }catch (phoneException phoneExcetion){
            System.err.println("电话号码重复");
        }catch (idNumberException numberException){
            System.err.println("身份证号码重复");
        }
        return insert;
    }

    public static boolean update(String phone, EDelivery newE) {
        return dao.update(phone,newE);
    }

    public static boolean delete(String phone) {
        return dao.delete(phone);
    }
}
